# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
from django.db import models


# Create your models here.
# 添加完之后在控制台输入:
# python manage.py makemigrations
# Python manage.py migrate


class Articale(models.Model):
    title = models.CharField(max_length=32, default='Title')
    content = models.TextField(null=True)
    pub_time = models.DateTimeField(null=True)

    def __unicode__(self):
        return self.title
        # 将属性和属性值转换成dict 列表生成式

    def toDict(self):
        return dict([(attr, getattr(self, attr)) for attr in
                     [f.name for f in self._meta.fields]])


class UserBean(models.Model):
    name = models.CharField(max_length=32, default='Name')
    password = models.TextField(null=True)

    def __unicode__(self):
        return self.name

    def toDict(self):
        return dict([(attr, getattr(self, attr)) for attr in
                     [f.name for f in self._meta.fields]])


class SimpleType(models.Model):
    currentId = models.IntegerField()
    name = models.CharField(max_length=32, default='Name')
    content = models.TextField(null=True)
    img = models.TextField(null=True)

    def __unicode__(self):
        return self.name

    def toDict(self):
        return dict([(attr, getattr(self, attr)) for attr in
                     [f.name for f in self._meta.fields]])


class GoodsInfo(models.Model):
    currentId = models.IntegerField()
    name = models.CharField(max_length=32, default='Name')
    content = models.TextField(null=True)
    img = models.TextField(null=True)
    price = models.FloatField(default=0.0)
    description = models.TextField(null=True)

    def __unicode__(self):
        return self.name

    def toDict(self):
        return dict([(attr, getattr(self, attr)) for attr in
                     [f.name for f in self._meta.fields]])


class PersonInfo(models.Model):
    personId = models.IntegerField()
    name = models.CharField(max_length=32, default='Name')
    money = models.FloatField(default=0.0)
    piaonum = models.IntegerField(default=0)
    cardnum = models.IntegerField(default=0)

    def __unicode__(self):
        return self.name

    def toJson(self):

        return json.dumps(dict([(attr, getattr(self, attr)) for attr in
                                [f.name for f in self._meta.fields]]))

    def toDict(self):
        return dict([(attr, getattr(self, attr)) for attr in
                     [f.name for f in self._meta.fields]])


class TypeInfo(models.Model):
    typeId = models.CharField(max_length=5, default='00')
    name = models.CharField(max_length=32, default='Name')
    smallId = models.CharField(max_length=5, default='0001')

    def __unicode__(self):
        return self.name

    def toDict(self):
        return dict([(attr, getattr(self, attr)) for attr in
                     [f.name for f in self._meta.fields]])
